package br.com.cotec.dao.impl;

import java.io.Serializable;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Example;
import org.hibernate.criterion.Restrictions;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import br.com.cotec.dao.StatusDao;
import br.com.cotec.model.Posicao;
import br.com.cotec.model.Status;

public class StatusDaoImpl extends GenericDaoImpl<Status, Serializable> implements StatusDao{

	/**
	 * {@inheritDoc}
	 */
	public boolean exists(String name) {
		Status status = (Status) getByName(name, new Status());
		return status != null;
	}
	
	/**
	 * {@inheritDoc}
	 */
	@SuppressWarnings("unchecked")
	@Transactional(propagation = Propagation.REQUIRED)
	public List<Status> getStatusParaAtendimento() {
		Session hibernateSession = (Session) em.getDelegate();
		Criteria criteria = hibernateSession.createCriteria(Status.class, "st");
		criteria.add(Restrictions.eq("st.sistema", false));

		return (List<Status>)criteria.list();
	}
	
	/**
	 * {@inheritDoc}
	 */
	@SuppressWarnings("unchecked")
	@Transactional(propagation = Propagation.REQUIRED)
	public List<Status> getStatusListaForm() {
		Session hibernateSession = (Session) em.getDelegate();
		Criteria criteria = hibernateSession.createCriteria(Status.class, "st");
		criteria.add(Restrictions.eq("st.usuario", Status.USUARIO));
		criteria.add(Restrictions.eq("st.sistema", false));
		
		return (List<Status>)criteria.list();
	}
}